package com.itheima.reggie.controller;

import com.itheima.reggie.domain.Category;
import com.itheima.reggie.service.CategoryService;
import com.itheima.reggie.common.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CategoryController {
    //调用service
    @Autowired
    private CategoryService categoryService;
    //编写查询所有方法
    @GetMapping("/category/findAll")
    public ResultInfo findAll(){
        List<Category> categoryList = categoryService.findAll();
        return ResultInfo.success(categoryList);
    }
    //编写添加方法 套餐和菜品公用一套路径
    @PostMapping("/category")
    public ResultInfo save(@RequestBody Category category){
        categoryService.save(category);
        return ResultInfo.success(null);
    }
    //程序已经回显 直接更新即可
    @PutMapping("/category")
    public  ResultInfo update(@RequestBody Category category){
        categoryService.update(category);
        return ResultInfo.success(null);
    }
    //删除方法
    @DeleteMapping("/category")
    public  ResultInfo delete(Long id){
       return categoryService.delete(id);
    }
    //回显
    @GetMapping("/category/list")
    public ResultInfo findList(Integer type){
        //调用查询方法
       List<Category> categoryList =categoryService.findList(type);
       return ResultInfo.success(categoryList);
    }
}
